<template>
  <div>
    <div class="train-info">
      <div class="item">
        <div class="icon" />
        <div class="context">
          <div class="label">在线车辆数</div>
          <div class="value">{{ tainInfo.online }}</div>
        </div>
      </div>

      <div class="item">
        <div class="icon" />
        <div class="context">
          <div class="label">离线车辆数</div>
          <div class="value">{{ tainInfo.offline }}</div>
        </div>
      </div>
    </div>

    <div class="device-info">
      <div class="item">
        <div class="icon" />
        <div class="context">
          <div class="label">在线设备数</div>
          <div class="value">{{ deviceInfo.online }}</div>
        </div>
      </div>

      <div class="item">
        <div class="icon" />
        <div class="context">
          <div class="label">离线设备数</div>
          <div class="value">{{ deviceInfo.offline }}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { queryNowTrainCount } from '@/api/statistics'

export default {
  name: 'CurrentTrain',
  data() {
    return {
      timer: null,
      tainInfo: {
        online: 40,
        offline: 5
      },
      deviceInfo: {
        online: 453,
        offline: 102
      }
    }
  },
  mounted() {
    this.refreshInfo()
    this.timer = setInterval(() => {
      this.refreshInfo()
    }, 2000)
  },
  beforeDestroy() {
    clearInterval(this.timer)
  },
  methods: {
    refreshInfo() {
      // queryNowTrainCount().then(res => {
      //   // this.info.online = parseInt(Math.random() * 1000);
      //   // this.info.offline = parseInt(Math.random() * 1000);
      //   this.info.online = res.data.onlineCount
      //   this.info.offline = res.data.offlineCount
      // })
    }
  }
}
</script>

<style lang="scss" scoped>
.train-info {
  color: #fff;
  padding: 16px 5px;
  display: flex;
  justify-content: space-between;
  align-items: center;

  .item {
    display: flex;
    justify-content: space-between;
    align-items: center;

    &:first-child {
      color: #0ef9b8;

      .icon {
        background-image: url('../../../assets/train-icon.png');
      }
    }
    &:last-child {
      color: #8a8a8a;
      .icon {
        background-image: url('../../../assets/train-icon-disabled.png');
      }
    }
  }
  .icon {
    width: 44px;
    height: 44px;

    background-size: cover;
    margin-right: 12px;
  }

  .label {
    font-size: 12px;
  }

  .value {
    font-weight: bold;
    margin-top: 6px;
    text-align: center;
  }
}

.device-info {
  color: #fff;
  padding: 16px 5px;
  display: flex;
  justify-content: space-between;
  align-items: center;

  .item {
    display: flex;
    justify-content: space-between;
    align-items: center;

    &:first-child {
      color: #0ef9b8;

      .icon {
        background-image: url('../../../assets/device-icon.png');
      }
    }
    &:last-child {
      color: #8a8a8a;
      .icon {
        background-image: url('../../../assets/device-icon-disabled.png');
      }
    }
  }
  .icon {
    width: 44px;
    height: 44px;

    background-size: cover;
    margin-right: 12px;
  }

  .label {
    font-size: 12px;
  }

  .value {
    font-weight: bold;
    margin-top: 6px;
    text-align: center;
  }
}
</style>
